import Vue from 'vue'
import Router from 'vue-router'

import Login from '@/pages/login'
import layout from '@/pages/layout'
import form from '@/pages/form'
import table from '@/pages/table'
import tree from '@/pages/tree'
import test from '@/pages/test'
import slots from '@/pages/slots'
import mixin from '@/pages/mixin'
import allEmit from '@/pages/allEmit'
// 进度条
import NProgress from 'nprogress' // progress bar
// import CompTable from '@/components/CompTable'

// Vue.use(CompTable)
Vue.use(Router)

const routes = [
  {
    path: '/',
    name: 'login',
    component: Login
  },
  {
    path: '/layout',
    redirect: '/table',
    component: layout,
    children: [
      {
        path: '/form',
        component: form
      },
      {
        path: '/table',
        component: table
      },
      {
        path: '/tree',
        component: tree
      },
      {
        path: '/test',
        component: test
      },
      {
        path: '/slots',
        component: slots
      },
      {
        path: '/mixin',
        component: mixin
      },
      {
        path: '/allEmit',
        component: allEmit
      }
    ]
  }
]

const route = new Router({
  routes
})

route.beforeEach((to, form, next) => {
  NProgress.start()
  next()
})

// 全局后置钩子
route.afterEach(() => {
  // finish progress bar 进度条结束
  NProgress.done()
})
export default route
